#!/usr/bin/env python
from collections import deque



def AStat(r,  c,  pacman_r,  pacman_c,  food_r,  food_c,  grid):
    data = []
    for i in range(r):
        hold =[]
        for j in range(c):
            if(grid[i][j]=='%'):
               hold.append(1)
            else :
               hold.append(0)       
        data.append(hold)
        
    #print (data)
    
    AStatSearch(data,[pacman_r,  pacman_c],[food_r,  food_c])
        

def heuristic(data,cell1,cell2,cell3):
    return abs(cell3[0]-cell1[0])+abs(cell3[1]-cell2[1])    

def AStatSearch(data,cell1,cell2):

    state = []
    pi =[]
    for i in range(len(data)):
        hold = [-1 for x in range(len(data[0]))]
        hold1 = [(-1,-1) for x in range(len(data[0]))]
        state.append(hold);
        pi.append(hold1);    
    q =[]
    q.append(cell1)
    ans = []
    state[cell1[0]][cell1[1]]=0
    while(len(q)!=0) :
        p = q.pop(0)
        
        ans.append(p)
        if(p[0]==cell2[0] and p[1]==cell2[1]) :
            print(len(ans))
            for i in ans:
                print(str(i[0])+" "+str(i[1]))
             
            ans =[]
            ans.append(list(p))
            while(p[0]!=cell1[0] or  p[1]!=cell1[1]):                
                p[0],p[1]=pi[p[0]][p[1]][0],pi[p[0]][p[1]][1]
                ans.append(list(p))
            
            ans.reverse()  
            print (len(ans)-1)
            for i in ans:
                print(str(i[0])+" "+str(i[1]))
             
            break;    
            
        
        x1 = p[0]-1
        y1 = p[1]
        if(x1>=0 and data[x1][y1]==0 and state[x1][y1]==-1):
            pi[x1][y1] = p
            q.append([x1,y1])
            state[x1][y1]=0
        
        x1 = p[0]
        y1 = p[1]-1
        if(y1>=0 and data[x1][y1]==0 and state[x1][y1]==-1):
            pi[x1][y1] = p
            q.append([x1,y1])
            state[x1][y1]=0
            
            
        x1 = p[0]
        y1 = p[1]+1
        if(y1<len(data[0]) and data[x1][y1]==0 and state[x1][y1]==-1):
            pi[x1][y1] = p
            q.append([x1,y1])
            state[x1][y1]=0
        
        x1 = p[0]+1
        y1 = p[1]
        if(x1<len(data) and data[x1][y1]==0 and state[x1][y1]==-1):
            pi[x1][y1] = p
            q.append([x1,y1])
            state[x1][y1]=0
        
        state[p[0]][p[1]]=1    


x = input()
y = x.split()
for i in range(len(y)):
    y[i] = int(y[i])


x = input()
z = x.split()
for i in range(len(z)):
    z[i] = int(z[i])

x = input()
a = x.split()
for i in range(len(a)):
    a[i] = int(a[i])

data = []
for i in range(a[0]):
    x = input()          
    data.append(x)

AStat(a[0],a[1],y[0],y[1],z[0],z[1],data)